#
# @lc app=leetcode.cn id=21 lang=python3
#
# [21] 合并两个有序链表
#

# @lc code=start
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
        if l1 == None: return l2
        if l2 == None: return l1
        
        if l1.val >= l2.val:
            resultLD = l2
            currentNode = l2
            l2 = l2.next
        else:
            resultLD = l1
            currentNode = l1
            l1 = l1.next
            
        
        while l1 != None and l2 != None:
            if l1.val >= l2.val:
                currentNode.next = l2
                currentNode = l2
                l2 = l2.next
            else:
                currentNode.next = l1
                currentNode = l1
                l1 = l1.next
        
        if l1 == None:
            currentNode.next = l2
            return resultLD
        else:
            currentNode.next = l1
            return resultLD
            
        
# @lc code=end